function load_event_functions()

	-- misc functions used by events
	-- this area is most likely a product of my poor coding habits

	e_funcs = {
		[1] = function(self) -- checks location at self.xy and x+1
			if (pX == self.x and pY == self.y)
				or (pX == self.x+1
				and pY == self.y) then

				return true

			else

				return false

			end
		end,

		[2] = function(self) -- event toggles true when not at self.xy or x+1
			if (pX == self.x and pY == self.y)
				or (pX == self.x+1
				and pY == self.y) then

			else

				self.toggle = true

			end
		end,

		[3] = function(self) -- player is here = true


				if pX == self.x and pY == self.y then


					return true

				else

					return false

				end


			end,

		[4] = function(self) -- player is not here = true

				if pX ~= self.x and pY ~= self.y then
					return true
				else
					return false

				end


			end,


	}

end

Event = class('Event')

-- My events are fucking baller
-- init them with functions for condition, effect, and anti
-- cond is what must be met to trigger the event
-- effect is what happens when the event triggers
-- anti needs tweaking, eventually is the opposite of condition,
-- or just another place to throw a function in
function Event:initialize(name, x, y, condition, effect, anti)

	self.name = name or "default event"
	self.x = x or 0
	self.y = y or 0
	self.triggered = false
	self.toggle = false
	self.on = false
	self.condition = condition or {
		[1] = function(self)
				print("default condition for", self.name)
				return false
			end, }
	self.effect = effect or {
		[1] = function(self)
				print("default effect for", self.name)
			end, }

	self.anti = anti or {
		[1] = function(self)



			end, }

	self.scaleX = scale
	self.scaleY = scale
	self.rotation = 0

	self.lit = false

	print("init event : ", self.x, self.y)
	events[#events+1] = self

end

function Event:update(dt)

	-- check for triggerable events

	for i = #events, 1, -1 do
		trig_index = i
		if events[i] then
			events[i]:trigger()
			if player.light then
				if p_light_beam_collide(events[i].x+tile_size*scale,
					events[i].y+tile_size*scale) then
					self.lit = true
				else
					self.lit = false
				end
			end
		end
	end

end

function Event:togg()

	-- events have a toggle, to be used
	-- at the programmers discretion
	-- this toggles the toggle

	if self.toggle then
		self.toggle = false
		return false
	else
		self.toggle = true
		return true
	end

end

function Event:trigger(...)

	-- we trigger the event

	-- we may add a table of functions to fire off
	local args = {...}

	for i = 1, #args do
		if args[i] then
			args[i]()
		end

	end


	if self.condition then -- if there is a condition

			if (self.triggered == false or self.toggle == true) then
			-- has not been triggered yet, or toggle override enabled

				for i = 1, #self.condition do
					--if self.condition[i] then
						if self.condition[i](self) then -- if the condition is met

							self.triggered = true -- we are triggered
							if self.effect[i] then -- we have an event to do

								self.effect[i](self)
								events[trig_index] = nil -- event over, kill self

							end

						else -- condition failed trigger anti

							if self.anti[i] then

								self.anti[i](self)

							end

						end
					--end


				end


			end

	end

end

function Event:draw()

	if self.lit or SceneCompletelyLit then
		draw_light(self.image, 
		dOX+((self.x-map_x)*(tile_size*scale)),
		dOY+((self.y-map_y)*(tile_size*scale)),
		self.rotation, self.scaleX, self.scaleY)
	else
		draw_dark(self.image, 
			dOX+((self.x-map_x)*(tile_size*scale)),
			dOY+((self.y-map_y)*(tile_size*scale)),
			self.rotation, self.scaleX, self.scaleY)
	end

end

function Event:draw_all()

	for i = 1, #events do
		if events[i] then
			if events[i].image then
				events[i]:draw()
			end
		end
	end

end

SoundEvent = class('SoundEvent', Event)

--- BBBREEAAAAAAAAAAACCCCCHHHHHHH MAKE SOME NOOIIISSEEE
function SoundEvent:initialize(name, x, y, sound)

	self.name = name or "default sound event"
	self.x = x or 0
	self.y = y or 0
	self.sound = sound or help_us_aud



	self.condition = {

	[1] = function(self)
			return e_funcs[3](self) -- ARE YOU ON THE SOUND SPOT????
		end,


	}


	self.effect = {

	[1] = function(self)

			print(self.sound)

			TEsound.play(self.sound) -- MAK DA SOUNDS

		end,

	}

	self.anti = {

	[1] = function(self)

			if e_funcs[4](self) then

			else

			end


		end,

	}

	Event.initialize(self, self.name, self.x, self.y,
		self.condition, self.effect)


end

function SoundEvent:multi(locs)

	-- sound event at locs = { {x = , y = }, }

	for i = 1, #locs do

		local snd = SoundEvent:new("sd "..i,
			locs[i].x, locs[i].y, locs[i].sound)

	end

end
--[[
MapTran = class('MapTran', Event)
-- map transitions
-- BUGGY use Elevator features instead

function MapTran:initialize(name, x, y, dest)

	self.name = name or "default maptran"

	self.x = x or 0
	self.y = y or 0

	dest = dest or 'Menu'

	self.image = metal_door_closed_img




	self.condition = {

	[1] = function(self)
			return e_funcs[3](self) -- do you stand here?????

		end,

	}

	self.effect = {

	[1] = function(self)

			gs:gotoState(dest) -- GOTO THARR

		end,

	}

	print("init :", self.x, self.y)
	print(self.condition[i])
	Event.initialize(self, self.name, self.x,
		self.y, self.condition, self.effect)
end

function MapTran:multi(locs)

	-- do you stand on any of theseseses?
	-- gobble to them
	-- locs = { {x =, y =, dest = }, }

	for i = #locs, 1, -1 do
		print("maptran loc at " .. locs[i].x .. " " .. locs[i].y)
		local mt = MapTran:new("mt "..i,locs[i].x, locs[i].y, locs[i].dest)

	end

end

function MapTran:multi2(points, dest)

	-- slightly diff way of packing same information as multi
	-- points = { {x =, y =}, }

	for i = 1, #points do

		local mt = MapTrain:new("mt "..i, points[i].x, points[i].y, dest)

	end

end

]]
